#################################################################################
# Filename: 4_round1_mediation.R
# Description: Takes the cleaned round 1 data and performs
# mediation analysis displayed in Appendix D
#################################################################################
# Library dependency
library(mediation)


# Import cleaned data from 1_round1_loaddata
dat <- import("Round_1_clean.Rdata") 

#Remove NAs for outcome, mediator
data <- dat[is.na(dat$antiforeign_pca)==FALSE,]
data <- data[is.na(data$Q19_1)==FALSE,]
data <- data[which(data$clip!="leopard"),]

#Linear regressions of treatment on mediator, mediator and treatment on outcome
med.fit <- lm(Q19_1~clip, data=data)
out.fit <- lm(antiforeign_pca~Q19_1+ clip, data=data)
med.out <- mediate(med.fit, out.fit, treat = "clip", mediator = "Q19_1", robustSE = TRUE, sims = 5000)

#Results
summary(med.out)


pdf("r1_mediation_news.pdf")
par(mar=c(7,8,1, 1) )
plot(med.out, xlab="Round 1: Hard propaganda: News broadcast", yaxt = "n", cex=2, cex.lab=1.5, col = "red", xlim=c(-0.15, 0.5))
axis(2, at=1:3, labels=c("Total\nEffect", "Direct\nEffect", "Effect\nMediated\nby Anger"), las=2, cex.axis=1.5)
dev.off()

data <- dat[is.na(dat$antiforeign_pca)==FALSE,]
data <- data[is.na(data$Q19_1)==FALSE,]
data <- data[which(data$clip!="yongbu"),]

#Linear regressions of treatment on mediator, mediator and treatment on outcome
med.fit <- lm(Q19_1~clip, data=data)
out.fit <- lm(antiforeign_pca~Q19_1+ clip, data=data)
med.out <- mediate(med.fit, out.fit, treat = "clip", mediator = "Q19_1", robustSE = TRUE, sims = 5000)

#Results
summary(med.out)


pdf("r1_mediation_drama.pdf")
par(mar=c(7,8,1, 1) )
plot(med.out, xlab="Round 1: Soft propaganda: Television drama", yaxt = "n", cex=2, cex.lab=1.5, col = "red", xlim=c(-0.15, 0.5))
axis(2, at=1:3, labels=c("Total\nEffect", "Direct\nEffect", "Effect\nMediated\nby Anger"), las=2, cex.axis=1.5)

dev.off()



#Remove NAs for outcome, mediator
data <- dat[is.na(dat$antiforeign_pca)==FALSE,]
data <- data[is.na(data$Q19_2)==FALSE,]
data <- data[which(data$clip!="leopard"),]

#Linear regressions of treatment on mediator, mediator and treatment on outcome
med.fit <- lm(Q19_2~clip, data=data)
out.fit <- lm(antiforeign_pca~Q19_2+ clip, data=data)
med.out <- mediate(med.fit, out.fit, treat = "clip", mediator = "Q19_1", robustSE = TRUE, sims = 5000)

#Results
summary(med.out)


pdf("r1_mediation_news_fear.pdf")
par(mar=c(7,8,1, 1) )
plot(med.out, xlab="Round 1: Anti-Japan news broadcast", yaxt = "n", cex=2, cex.lab=1.5, col = "red", xlim=c(-0.15, 0.5))
axis(2, at=1:3, labels=c("Total\nEffect", "Direct\nEffect", "Effect\nMediated\nby Anger"), las=2, cex.axis=1.5)
dev.off()


data <- dat[is.na(dat$antiforeign_pca)==FALSE,]
data <- data[is.na(data$Q19_1)==FALSE,]
data <- data[which(data$clip!="yongbu"),]

#Linear regressions of treatment on mediator, mediator and treatment on outcome
med.fit <- lm(Q19_1~clip, data=data)
out.fit <- lm(antiforeign_pca~Q19_1+ clip, data=data)
med.out <- mediate(med.fit, out.fit, treat = "clip", mediator = "Q19_1", robustSE = TRUE, sims = 5000)

#Results
summary(med.out)


pdf("r1_mediation_drama_fear.pdf")
par(mar=c(7,8,1, 1) )
plot(med.out, xlab="Round 1: Anti-Japanese War Drama", yaxt = "n", cex=2, cex.lab=1.5, col = "red", xlim=c(-0.15, 0.5))
axis(2, at=1:3, labels=c("Total\nEffect", "Direct\nEffect", "Effect\nMediated\nby Anger"), las=2, cex.axis=1.5)

dev.off()

